﻿/****************************************************************************
Copyright (c) 2014-2015 凌惊雪 微信:Lingjingxue 邮箱:lingjingxue@sina.com QQ:271487457

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
****************************************************************************/

using UtilPublic.ServerLoger;
using ServerBase.Service;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Xml.Linq;
using UtilLib;

namespace ServerBase.Config
{
    /// <summary>
    /// 配置文件
    /// </summary>
    public static partial class Conf
    {
        #region 全局ID EGlobalId
        public static string Value(this EGlobalId GlobalId) => (ConfGlobal[GlobalId].Value);
        public static bool ValueBool(this EGlobalId GlobalId) => (ConfGlobal[GlobalId].ValueBool);
        public static int ValueInt(this EGlobalId GlobalId) => (ConfGlobal[GlobalId].ValueInt);
        public static long ValueLong(this EGlobalId GlobalId) => (ConfGlobal[GlobalId].ValueLong);
        public static float ValueFloat(this EGlobalId GlobalId) => (ConfGlobal[GlobalId].ValueFloat);
        public static List<string> ValueListString(this EGlobalId GlobalId) => (ConfGlobal[GlobalId].ValueListString);
        public static List<int> ValueListInt(this EGlobalId GlobalId) => (ConfGlobal[GlobalId].ValueListInt);
        public static List<float> ValueListfloat(this EGlobalId GlobalId) => (ConfGlobal[GlobalId].ValueListfloat);
        public static List<List<int>> ValueListListInt(this EGlobalId GlobalId) => (ConfGlobal[GlobalId].ValueListListInt);
        #endregion

        #region 返回码 EProtocolResult
        public static bool Success(this EProtocolResult result)
        {
            return result == EProtocolResult.成功;
        }
        #endregion

        #region 多语言字符串
        //获取多语言字符串
        public static string TextLanguage(this string text)
        {
            string result = text;
            if (ConfLanguage.TryGetValue(text, out var conf))
            {
                switch (BaseServerInfo.Language)
                {
                    case ELanguage.英语:
                        result = conf.LangEn;
                        break;
                    case ELanguage.韩语:
                        result = conf.LangKo;
                        break;
                    default:
                        result = conf.LangChs;
                        break;
                }
            }
            if (result == null)
            {
                result = "";
            }
            return result;
        }
        //获取邮件字符串
        public static string TextMail(this EMailText text)
        {
            string result = text.ToString();
            if (ConfMailText.TryGetValue((int)text, out var conf))
            {
                switch (BaseServerInfo.Language)
                {
                    case ELanguage.英语:
                        result = conf.LangEn;
                        break;
                    case ELanguage.韩语:
                        result = conf.LangKo;
                        break;
                    default:
                        result = conf.LangChs;
                        break;
                }
            }
            if (result == null)
            {
                result = "";
            }
            return result;
        }
        // 添加记录
        public static string TextMail(this EMailText text, params object[] args)
        {
            return string.Format(text.TextMail(), args);
        }
        #endregion

        public static string ColorSp(this ConfigFamily conf)
        {
            return $"#{conf.Color}#";
        }
        public static string ColorName(this ConfigFamily conf)
        {
            return $"#{conf.Color}#{conf.Name}#NOR#";
        }
        public static string ColorName(this ConfigDescLevel conf)
        {
            return $"#{conf.Color}#{conf.Desc}#NOR#";
        }

    }

}